#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define URL_UNSAFE "<>\"#%{}|\\^~[]'@:\033"
/* ASCII char -> HEX digit */
#define ASC2HEXD(x) (((x) >= '0' && (x) <= '9') ?               \
		     ((x) - '0') : (toupper(x) - 'A' + 10))

/* HEX digit -> ASCII char */
#define HEXD2ASC(x) (((x) < 10) ? ((x) + '0') : ((x) - 10 + 'A'))
#define ISASCII(x)  isascii ((unsigned char)(x))
#define ISALPHA(x)  isalpha ((unsigned char)(x))
#define ISSPACE(x)  isspace ((unsigned char)(x))
#define ISDIGIT(x)  isdigit ((unsigned char)(x))
#define ISXDIGIT(x) isxdigit ((unsigned char)(x))
void *
xmalloc (size_t size)
{
  void *res;

  res = malloc (size);
  if (!res)
    printf("abc");
  return res;
}

void decode_string (char *s)
{
  char *p = s;

  for (; *s; s++, p++)
    {
      if (*s != '%')
	*p = *s;
      else
	{
	  /* Do nothing if at the end of the string, or if the chars
	     are not hex-digits.  */
	  if (!*(s + 1) || !*(s + 2)
	      || !(ISXDIGIT (*(s + 1)) && ISXDIGIT (*(s + 2))))
	    {
	      *p = *s;
	      continue;
	    }
	  *p = (ASC2HEXD (*(s + 1)) << 4) + ASC2HEXD (*(s + 2));
	  s += 2;
	}
    }
  *p = '\0';
}

char * encode_string (const char *s)
{
  const char *b;
  char *p, *res;
  int i;

  b = s;
  for (i = 0; *s; s++, i++)
    if (strchr (URL_UNSAFE, *s))
      i += 2; /* Two more characters (hex digits) */
  res = (char *)xmalloc (i + 1);
  s = b;
  for (p = res; *s; s++)
    if (strchr (URL_UNSAFE, *s))
      {
	const unsigned char c = *s;
	*p++ = '%';
	*p++ = HEXD2ASC (c >> 4);
	*p++ = HEXD2ASC (c & 0xf);
      }
    else
      *p++ = *s;
  *p = '\0';
  return res;
}




int main(int argc,char **argv)
{
  char *env = getenv("PATH");
  printf("%d",access("C:/2.txt",F_OK));
  printf("\n");
  //  printf("%s",env);

  char * str = "abc def";
  printf("%d",sizeof(*(str)));
  printf("\n");
  char *s = "\:";

  printf("%d",strchr(URL_UNSAFE,*s));
  printf("\n");
  char *s1 = "http://tieba.baidu.com/f?kw=/%3F%5E%5C";
  printf("%s",encode_string(s1));

  return 0;
}
